package com.rjpacket.chileme.app.tasks;

import android.os.AsyncTask;
import com.rjpacket.chileme.app.utils.HttpTool;
import org.json.JSONObject;

/**
 * Created by WIN7 on 2015/3/24.
 */
public class StoreListTask extends AsyncTask<String,Integer,JSONObject>{

    private ListTaskInterface inter;

    public StoreListTask(ListTaskInterface inter) {
        this.inter = inter;
    }

    @Override
    protected JSONObject doInBackground(String... params) {

        JSONObject ret = null;

        if (params!=null && params.length>0){
            String url = params[0];

            byte[] bytes = HttpTool.get(url);
            if (bytes != null) {

                try {
                    String data = new String(bytes,"UTF-8");
                    ret = new JSONObject(data);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {

        if (inter != null) {
            inter.processListResult(jsonObject);
        }

    }
}
